package cn.bugstack.trigger.http;


import cn.bugstack.api.response.IDCCService;
import cn.bugstack.api.response.Response;
import cn.bugstack.types.enums.ResponseCode;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.builder.qual.ReturnsReceiver;
import org.redisson.api.RTopic;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@Slf4j
@CrossOrigin(origins = "*")
@RequestMapping("/api/v1/gbm/dcc")
public class DCCController implements IDCCService {
    @Resource
    private RTopic dccTopic;
    @RequestMapping("/update_config")
    @Override
    public Response<Boolean> updateConfig(String key, String value) {
        try{
            dccTopic.publish(key + ":" + value);
            return Response.<Boolean>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .build();
        }
        catch (Exception e){
            return Response.<Boolean>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .build();
        }
    }
}
